var GameData = require('../module/gameData')();
var that;
cc.Class({
    extends: cc.Component,

    properties: {},

    // LIFE-CYCLE CALLBACKS:

    onLoad() {


    },
    onEnable() {
        that = this;
        that.node.getChildByName("musicBg").on(cc.Node.EventType.TOUCH_START, that.onTouchStart, that);

        that.node.getChildByName("musicbg1").runAction(cc.sequence(
            cc.scaleTo(0.3, 1.2),
            cc.scaleTo(0.2, 1),
        ))
        let _node = this.node.getChildByName("musicbg1");
        if (GameData.bgMusic) {
            _node.getChildByName("up").active = true;
            _node.getChildByName("upoff").active = false;
        } else {
            _node.getChildByName("up").active = false;
            _node.getChildByName("upoff").active = true;
        }
        if (GameData.bgEffect) {
            _node.getChildByName("down").active = true;
            _node.getChildByName("downoff").active = false;
        } else {
            _node.getChildByName("down").active = false;
            _node.getChildByName("downoff").active = true;
        }
    },
    onTouchStart() {
        that.node.getChildByName("musicbg1").runAction(cc.sequence(
            cc.scaleTo(0.2, 1.2),
            cc.scaleTo(0.3, 0),
            cc.callFunc(function () {
                cc.find("musicLayer").active = false;
            })
        ))
    },
    selectBtn(evt) {
        let _name = evt.currentTarget.name;
        let _node = this.node.getChildByName("musicbg1");
        switch (_name) {
            case "up":/* 音乐关闭 */
                GameData.bgMusic = false;
                _node.getChildByName("up").active = false;
                _node.getChildByName("upoff").active = true;

                GameData.stopMusic();
                break;
            case "upoff":/* 音乐开启 */
                GameData.bgMusic = true;
                _node.getChildByName("up").active = true;
                _node.getChildByName("upoff").active = false;
                cc.audioEngine.resumeMusic();
                break;
            case "down":/* 音效关闭 */
                GameData.bgEffect = false;
                _node.getChildByName("down").active = false;
                _node.getChildByName("downoff").active = true;
                // GameData.stopAllEffects();
                break;
            case "downoff":/* 音效开启 */
                GameData.bgEffect = true;
                _node.getChildByName("down").active = true;
                _node.getChildByName("downoff").active = false;
                break;

        }
    },
    start() {

    },

    // update (dt) {},
});
